.data
  s: .long 2			          # values
	z: .long 3
	result: .string "%d\n"		# string to print result

.text
.globl main
main:

	movl s, %eax			        # s into %eax
	movl z, %ebx			        # z into %ebx
	
	pushl %eax			          # push %eax into stack
	pushl %ebx			          # push %ebx into stack
	subl $4, %esp		       	# open stack for return element
	call pascal			         # call pascal	

	pushl %eax			          # push %eax into stack	
	pushl $result			       # push string with result into stack
	call printf			         # print return
	addl $12, %esp			
	
	movl $1, %eax			       # exit
	int $0x80			           # software interrupt

pascal:
	pushl %ebp			          # push basepointer into stack
	movl %esp, %ebp		

	movl 16(%ebp), %eax		   # move 16(%ebp)(s) into %eax
	movl 12(%ebp), %ebx		   # move 12(%ebp)(z) into %ebx
	
	cmpl $1, %eax			       # if s == 1
	je .endpascal			       # go to endpascal
	cmpl $1, %ebx			       # if z == 1
	je .endpascal			       # go to endpascal
	
	//p(z - 1,s)
	subl $1, %ebx			       # z - 1
	//
	
	pushl %eax			          # push %eax into stack
	pushl %ebx			          # push %ebx into stack
	subl $4, %esp			       # storage for result 1

	call pascal			         # call pascal again

	addl $4, %esp			       # forget old result 1
	popl %eax			           # pop %eax
	popl %ebx			           # pop %ebx
	
	//p(z - 1,s - 1)
	subl $1, %eax			       # s - 1
	subl $1, %ebx			       # z - 1
	//

	pushl %eax			          # push %eax into stack
	pushl %ebx			          # push %ebx into stack
	subl $4, %esp			       # storage for result 2
	
	call pascal			         # call pascal again

	addl $4, %esp			       # forget old result 2
	popl %eax			           # pop %eax
  popl %ebx			           # pop %ebx
	addl %ebx, %eax			     # p(z - 1,s) + p(z - 1,s - 1)

	movl %eax, 8(%esp)		    # move result into 8 of %esp
	popl %ebp
	ret

.endpascal:
	movl $1, 8(%esp)
	popl %ebp
	ret